package com.ruoyi.qywx.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.NumberUtils;
import com.ruoyi.qywx.entity.QyWelcomeTemplate;
import com.ruoyi.qywx.mapper.WelcomeMapper;
import com.ruoyi.qywx.service.inters.WelcomeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author : hcl
 * @Date : 2023/8/2
 */
@Service
public class WelcomeServiceImpl implements WelcomeService {
    @Resource
    private WelcomeMapper welcomeMapper;

    @Transactional
    @Override
    public int insert(QyWelcomeTemplate welcomeTemplate) {
        if (NumberUtils.isTrue(welcomeTemplate.getId())) {
            return update(welcomeTemplate);
        } else {
            return welcomeMapper.insert(welcomeTemplate);
        }
    }

    @Override
    public QyWelcomeTemplate selectById(Long id) {
        if (NumberUtils.isTrue(id)) {
            return welcomeMapper.selectById(id);
        }
        return null;
    }

    @Transactional
    @Override
    public int update(QyWelcomeTemplate qyWelcomeTemplate) {
        return welcomeMapper.updateById(qyWelcomeTemplate);
    }

    @Transactional
    @Override
    public int deleteById(Long id) {
        if (NumberUtils.isTrue(id)) {
            return welcomeMapper.deleteById(id);
        }
        return 0;
    }

}
